// Licensed to Elasticsearch B.V under one or more agreements.
// Elasticsearch B.V licenses this file to you under the Apache 2.0 License.
// See the LICENSE file in the project root for more information.
//
// ███╗   ██╗ ██████╗ ████████╗██╗ ██████╗███████╗
// ████╗  ██║██╔═══██╗╚══██╔══╝██║██╔════╝██╔════╝
// ██╔██╗ ██║██║   ██║   ██║   ██║██║     █████╗
// ██║╚██╗██║██║   ██║   ██║   ██║██║     ██╔══╝
// ██║ ╚████║╚██████╔╝   ██║   ██║╚██████╗███████╗
// ╚═╝  ╚═══╝ ╚═════╝    ╚═╝   ╚═╝ ╚═════╝╚══════╝
// ------------------------------------------------
//
// This file is automatically generated.
// Please do not edit these files manually.
//
// ------------------------------------------------

#nullable restore

using Elastic.Clients.Elasticsearch.Serverless.Fluent;
using Elastic.Clients.Elasticsearch.Serverless.Serialization;
using System;
using System.Collections.Generic;
using System.Linq.Expressions;
using System.Text.Json;
using System.Text.Json.Serialization;

namespace Elastic.Clients.Elasticsearch.Serverless.MachineLearning;

public sealed partial class DataframeAnalysisFeatureProcessorFrequencyEncoding
{
	/// <summary>
	/// <para>
	/// The resulting feature name.
	/// </para>
	/// </summary>
	[JsonInclude, JsonPropertyName("feature_name")]
	public Elastic.Clients.Elasticsearch.Serverless.Name FeatureName { get; set; }
	[JsonInclude, JsonPropertyName("field")]
	public Elastic.Clients.Elasticsearch.Serverless.Field Field { get; set; }

	/// <summary>
	/// <para>
	/// The resulting frequency map for the field value. If the field value is missing from the frequency_map, the resulting value is 0.
	/// </para>
	/// </summary>
	[JsonInclude, JsonPropertyName("frequency_map")]
	public IDictionary<string, double> FrequencyMap { get; set; }

	public static implicit operator Elastic.Clients.Elasticsearch.Serverless.MachineLearning.DataframeAnalysisFeatureProcessor(DataframeAnalysisFeatureProcessorFrequencyEncoding dataframeAnalysisFeatureProcessorFrequencyEncoding) => Elastic.Clients.Elasticsearch.Serverless.MachineLearning.DataframeAnalysisFeatureProcessor.FrequencyEncoding(dataframeAnalysisFeatureProcessorFrequencyEncoding);
}

public sealed partial class DataframeAnalysisFeatureProcessorFrequencyEncodingDescriptor<TDocument> : SerializableDescriptor<DataframeAnalysisFeatureProcessorFrequencyEncodingDescriptor<TDocument>>
{
	internal DataframeAnalysisFeatureProcessorFrequencyEncodingDescriptor(Action<DataframeAnalysisFeatureProcessorFrequencyEncodingDescriptor<TDocument>> configure) => configure.Invoke(this);

	public DataframeAnalysisFeatureProcessorFrequencyEncodingDescriptor() : base()
	{
	}

	private Elastic.Clients.Elasticsearch.Serverless.Name FeatureNameValue { get; set; }
	private Elastic.Clients.Elasticsearch.Serverless.Field FieldValue { get; set; }
	private IDictionary<string, double> FrequencyMapValue { get; set; }

	/// <summary>
	/// <para>
	/// The resulting feature name.
	/// </para>
	/// </summary>
	public DataframeAnalysisFeatureProcessorFrequencyEncodingDescriptor<TDocument> FeatureName(Elastic.Clients.Elasticsearch.Serverless.Name featureName)
	{
		FeatureNameValue = featureName;
		return Self;
	}

	public DataframeAnalysisFeatureProcessorFrequencyEncodingDescriptor<TDocument> Field(Elastic.Clients.Elasticsearch.Serverless.Field field)
	{
		FieldValue = field;
		return Self;
	}

	public DataframeAnalysisFeatureProcessorFrequencyEncodingDescriptor<TDocument> Field<TValue>(Expression<Func<TDocument, TValue>> field)
	{
		FieldValue = field;
		return Self;
	}

	public DataframeAnalysisFeatureProcessorFrequencyEncodingDescriptor<TDocument> Field(Expression<Func<TDocument, object>> field)
	{
		FieldValue = field;
		return Self;
	}

	/// <summary>
	/// <para>
	/// The resulting frequency map for the field value. If the field value is missing from the frequency_map, the resulting value is 0.
	/// </para>
	/// </summary>
	public DataframeAnalysisFeatureProcessorFrequencyEncodingDescriptor<TDocument> FrequencyMap(Func<FluentDictionary<string, double>, FluentDictionary<string, double>> selector)
	{
		FrequencyMapValue = selector?.Invoke(new FluentDictionary<string, double>());
		return Self;
	}

	protected override void Serialize(Utf8JsonWriter writer, JsonSerializerOptions options, IElasticsearchClientSettings settings)
	{
		writer.WriteStartObject();
		writer.WritePropertyName("feature_name");
		JsonSerializer.Serialize(writer, FeatureNameValue, options);
		writer.WritePropertyName("field");
		JsonSerializer.Serialize(writer, FieldValue, options);
		writer.WritePropertyName("frequency_map");
		JsonSerializer.Serialize(writer, FrequencyMapValue, options);
		writer.WriteEndObject();
	}
}

public sealed partial class DataframeAnalysisFeatureProcessorFrequencyEncodingDescriptor : SerializableDescriptor<DataframeAnalysisFeatureProcessorFrequencyEncodingDescriptor>
{
	internal DataframeAnalysisFeatureProcessorFrequencyEncodingDescriptor(Action<DataframeAnalysisFeatureProcessorFrequencyEncodingDescriptor> configure) => configure.Invoke(this);

	public DataframeAnalysisFeatureProcessorFrequencyEncodingDescriptor() : base()
	{
	}

	private Elastic.Clients.Elasticsearch.Serverless.Name FeatureNameValue { get; set; }
	private Elastic.Clients.Elasticsearch.Serverless.Field FieldValue { get; set; }
	private IDictionary<string, double> FrequencyMapValue { get; set; }

	/// <summary>
	/// <para>
	/// The resulting feature name.
	/// </para>
	/// </summary>
	public DataframeAnalysisFeatureProcessorFrequencyEncodingDescriptor FeatureName(Elastic.Clients.Elasticsearch.Serverless.Name featureName)
	{
		FeatureNameValue = featureName;
		return Self;
	}

	public DataframeAnalysisFeatureProcessorFrequencyEncodingDescriptor Field(Elastic.Clients.Elasticsearch.Serverless.Field field)
	{
		FieldValue = field;
		return Self;
	}

	public DataframeAnalysisFeatureProcessorFrequencyEncodingDescriptor Field<TDocument, TValue>(Expression<Func<TDocument, TValue>> field)
	{
		FieldValue = field;
		return Self;
	}

	public DataframeAnalysisFeatureProcessorFrequencyEncodingDescriptor Field<TDocument>(Expression<Func<TDocument, object>> field)
	{
		FieldValue = field;
		return Self;
	}

	/// <summary>
	/// <para>
	/// The resulting frequency map for the field value. If the field value is missing from the frequency_map, the resulting value is 0.
	/// </para>
	/// </summary>
	public DataframeAnalysisFeatureProcessorFrequencyEncodingDescriptor FrequencyMap(Func<FluentDictionary<string, double>, FluentDictionary<string, double>> selector)
	{
		FrequencyMapValue = selector?.Invoke(new FluentDictionary<string, double>());
		return Self;
	}

	protected override void Serialize(Utf8JsonWriter writer, JsonSerializerOptions options, IElasticsearchClientSettings settings)
	{
		writer.WriteStartObject();
		writer.WritePropertyName("feature_name");
		JsonSerializer.Serialize(writer, FeatureNameValue, options);
		writer.WritePropertyName("field");
		JsonSerializer.Serialize(writer, FieldValue, options);
		writer.WritePropertyName("frequency_map");
		JsonSerializer.Serialize(writer, FrequencyMapValue, options);
		writer.WriteEndObject();
	}
}